﻿<!DOCTYPE html>
<html ng-app="demoApp" lang="en">
<head>
    <title id='Description'>AngularJS DataTable - Data Paging API</title>
    <meta name="description" content="This sample demonstrates how to implement Data Paging with JavaScript Grid" />
    <link rel="stylesheet" href="../../../jqwidgets/styles/jqx.base.css" type="text/css" />
    <script type="text/javascript" src="../../../scripts/angular.min.js"></script> 
    <script type="text/javascript" src="../../../scripts/jquery-1.11.1.min.js"></script>
    <script type="text/javascript" src="../../../jqwidgets/jqxcore.js"></script>
    <script type="text/javascript" src="../../../jqwidgets/jqxdata.js"></script> 
    <script type="text/javascript" src="../../../jqwidgets/jqxbuttons.js"></script>
    <script type="text/javascript" src="../../../jqwidgets/jqxscrollbar.js"></script>
    <script type="text/javascript" src="../../../jqwidgets/jqxlistbox.js"></script>
    <script type="text/javascript" src="../../../jqwidgets/jqxdropdownlist.js"></script>
    <script type="text/javascript" src="../../../jqwidgets/jqxdatatable.js"></script>
    <script type="text/javascript" src="../../../jqwidgets/jqxpanel.js"></script>
    <script type="text/javascript" src="../../../jqwidgets/jqxradiobutton.js"></script>
    <script type="text/javascript" src="../../../jqwidgets/jqxinput.js"></script>
    <script type="text/javascript" src="../../sampledata/generatedata.js"></script>
    <script type="text/javascript" src="../../../scripts/demos.js"></script>
    <script type="text/javascript" src="../../../jqwidgets/jqxangular.js"></script>
    <script type="text/javascript">
        var demoApp = angular.module("demoApp", ["jqwidgets"]); 
        demoApp.controller("demoController", function ($scope) {     
            $scope.page = 1;
            $scope.log = "";
            var grid;

            $scope.gridSettings =
            {
                width: 650,
                source: new $.jqx.dataAdapter({
                    localData: generateData(200),
                    dataType: "array",
                    datafields:
                    [
                        { name: 'firstname', type: 'string' },
                        { name: 'lastname', type: 'string' },
                        { name: 'productname', type: 'string' },
                        { name: 'quantity', type: 'number' },
                        { name: 'price', type: 'number' },
                        { name: 'total', type: 'number' }
                    ]
                }),                
                pagerPosition: 'both',
                pagerMode: 'default',
                created: function(args)
                {
                    grid = args.instance;
                },
                pageable: true,
                altRows: true,
                columns: [
                  { text: 'Name', dataField: 'firstname', width: 200 },
                  { text: 'Last Name', dataField: 'lastname', width: 200 },
                  { text: 'Product', editable: false, dataField: 'productname', width: 180 },
                  { text: 'Quantity', dataField: 'quantity', width: 80, cellsalign: 'right' },
                  { text: 'Unit Price', dataField: 'price', width: 80, cellsalign: 'right', cellsformat: 'c2' },
                  { text: 'Total', dataField: 'total', width: 80, cellsalign: 'right', cellsformat: 'c2' }
                ]
            };

            // Settings
            $scope.pagerModeDropDownList = { height: 25,  width: 120, selectedIndex: 0, source: ["default", "advanced"], autoDropDownHeight: true };
            $scope.pagerModeDropDownListSelect = function (event) {
                if (event.args.index == 0) {
                    $scope.gridSettings.pagerMode = "default";
                }
                else {
                    $scope.gridSettings.pagerMode = "advanced";
                }
            };
            $scope.pagerPositionDropDownList = { height: 25,  width: 120, selectedIndex: 2, source: ["top", "bottom", "both"], autoDropDownHeight: true };
            $scope.pagerPositionDropDownListSelect = function (event) {
                if (event.args.index == 0) {
                    $scope.gridSettings.pagerPosition = "top";
                }
                else if (event.args.index == 1) {
                    $scope.gridSettings.pagerPosition = "bottom";
                }
                else {
                    $scope.gridSettings.pagerPosition = "both";
                }
            };

        
            $scope.applyPage = function () {
                var page = parseInt($scope.page);
                if (!isNaN(page)) {
                    page--;
                    if (page < 0) page = 0;
                    grid.goToPage(page);
                }
            };

            $scope.pageChanged = function (event) {
                var args = event.args;
                var eventData = "Page:" + (1 + args.pagenum) + ", Page Size: " + args.pageSize;
                $scope.log = eventData;
            };

            $scope.pageSizeChanged = function (event) {
                var args = event.args;
                var eventData = "Page:" + (1 + args.pagenum) + ", Page Size: " + args.pageSize;
                $scope.log = eventData;
            };
        });
    </script>
</head>
 <body ng-controller="demoController">
    <jqx-data-table jqx-watch="[gridSettings.pagerPosition, gridSettings.pagerMode]" jqx-on-page-changed="pageChanged(event)" jqx-on-page-size-changed="pageSizeChanged(event)" jqx-settings="gridSettings" style="float: left;">
    </jqx-data-table>
    <div style="font-size: 13px; font-family: verdana; float: left; margin-left: 30px;">
        <div><strong>Settings</strong></div>
        <div style="margin-top: 10px;">
            <div>Pager Mode:</div>
            <jqx-drop-down-list jqx-on-select="pagerModeDropDownListSelect(event)" jqx-settings="pagerModeDropDownList" style="margin-top: 5px;"></jqx-drop-down-list>
            <div  style="margin-top: 10px;">Pager Position:</div>
            <jqx-drop-down-list jqx-on-select="pagerPositionDropDownListSelect(event)" jqx-settings="pagerPositionDropDownList" style="margin-top: 5px;"></div>
            <div  style="margin-top: 10px;">Go to Page:</div>
            <jqx-input jqx-height="25" jqx-width="120" ng-model="page" style="margin-top: 5px;"></jqx-input>
            <jqx-button jqx-on-click="applyPage()">Apply</jqx-button>
        </div>
        <div style="margin-top: 10px;">
            <div>Event Log:</div>
           {{log}}
        </div>    
</body>
</html>
